/**
 * 
 */
package com.cob.main;

/**
 * @author Donald
 */
public class CombatController {
	/**
	 * Table containing all indexed combat results. 1st row is the roll 2nd
	 * column is the weapon type
	 */
	private final int[][]	combatResultTable	= {
												{
												0, // WEAPON_TYPE_DAGGER
			0, // WEAPON_TYPE_THROW_DAGGER
			0, // WEAPON_TYPE_BOW
			0, // WEAPON_TYPE_SWORD
			0, // WEAPON_TYPE_HAMMER
			0, // WEAPON_TYPE_AX
			0									// WEAPON_TYPE_MONSTER
			}, // roll 1-3
			{
				0, // WEAPON_TYPE_DAGGER
			0, // WEAPON_TYPE_THROW_DAGGER
			0, // WEAPON_TYPE_BOW
			1, // WEAPON_TYPE_SWORD
			1, // WEAPON_TYPE_HAMMER
			1, // WEAPON_TYPE_AX
			0 // WEAPON_TYPE_MONSTER
			}, // roll 4
			{
				1, // WEAPON_TYPE_DAGGER
			0, // WEAPON_TYPE_THROW_DAGGER
			1, // WEAPON_TYPE_BOW
			1, // WEAPON_TYPE_SWORD
			1, // WEAPON_TYPE_HAMMER
			1, // WEAPON_TYPE_AX
			0 // WEAPON_TYPE_MONSTER
			}, // roll 5
			{
				1, // WEAPON_TYPE_DAGGER
			1, // WEAPON_TYPE_THROW_DAGGER
			1, // WEAPON_TYPE_BOW
			1, // WEAPON_TYPE_SWORD
			1, // WEAPON_TYPE_HAMMER
			1, // WEAPON_TYPE_AX
			1 // WEAPON_TYPE_MONSTER
			}, // roll 6-9
			{
				1, // WEAPON_TYPE_DAGGER
			1, // WEAPON_TYPE_THROW_DAGGER
			1, // WEAPON_TYPE_BOW
			2, // WEAPON_TYPE_SWORD
			2, // WEAPON_TYPE_HAMMER
			2, // WEAPON_TYPE_AX
			1 // WEAPON_TYPE_MONSTER
			}, // roll 10
			{
				2, // WEAPON_TYPE_DAGGER
			1, // WEAPON_TYPE_THROW_DAGGER
			2, // WEAPON_TYPE_BOW
			2, // WEAPON_TYPE_SWORD
			2, // WEAPON_TYPE_HAMMER
			2, // WEAPON_TYPE_AX
			1 // WEAPON_TYPE_MONSTER
			}, // roll 11
			{
				2, // WEAPON_TYPE_DAGGER
			2, // WEAPON_TYPE_THROW_DAGGER
			2, // WEAPON_TYPE_BOW
			2, // WEAPON_TYPE_SWORD
			3, // WEAPON_TYPE_HAMMER
			2, // WEAPON_TYPE_AX
			2 // WEAPON_TYPE_MONSTER
			}, // roll 12
			{
				2, // WEAPON_TYPE_DAGGER
			2, // WEAPON_TYPE_THROW_DAGGER
			2, // WEAPON_TYPE_BOW
			3, // WEAPON_TYPE_SWORD
			3, // WEAPON_TYPE_HAMMER
			3, // WEAPON_TYPE_AX
			2 // WEAPON_TYPE_MONSTER
			}, // roll 13
			{
				3, // WEAPON_TYPE_DAGGER
			2, // WEAPON_TYPE_THROW_DAGGER
			3, // WEAPON_TYPE_BOW
			3, // WEAPON_TYPE_SWORD
			4, // WEAPON_TYPE_HAMMER
			4, // WEAPON_TYPE_AX
			2 // WEAPON_TYPE_MONSTER
			}, // roll 14
			{
				3, // WEAPON_TYPE_DAGGER
			3, // WEAPON_TYPE_THROW_DAGGER
			3, // WEAPON_TYPE_BOW
			4, // WEAPON_TYPE_SWORD
			4, // WEAPON_TYPE_HAMMER
			4, // WEAPON_TYPE_AX
			3 // WEAPON_TYPE_MONSTER
			}, // roll 15
			{
				4, // WEAPON_TYPE_DAGGER
			3, // WEAPON_TYPE_THROW_DAGGER
			4, // WEAPON_TYPE_BOW
			4, // WEAPON_TYPE_SWORD
			5, // WEAPON_TYPE_HAMMER
			5, // WEAPON_TYPE_AX
			4 // WEAPON_TYPE_MONSTER
			}, // roll 16
			{
				4, // WEAPON_TYPE_DAGGER
			4, // WEAPON_TYPE_THROW_DAGGER
			4, // WEAPON_TYPE_BOW
			5, // WEAPON_TYPE_SWORD
			5, // WEAPON_TYPE_HAMMER
			5, // WEAPON_TYPE_AX
			5 // WEAPON_TYPE_MONSTER
			}									// roll 17
												};
	/** the maximum roll value possible. */
	private final int		maxRoll				= 17;
	/** the map of all rolls and their rows in the combatResultsTable. */
	private final int[]		rollMap				= {
												0, // roll 0 maps to
													// combatResultTable index 0
			0, // roll 1 maps to combatResultTable index 0
			0, // roll 2 maps to combatResultTable index 0
			0, // roll 3 maps to combatResultTable index 0
			1, // roll 4 maps to combatResultTable index 1
			2, // roll 5 maps to combatResultTable index 2
			3, // roll 6 maps to combatResultTable index 3
			3, // roll 7 maps to combatResultTable index 3
			3, // roll 8 maps to combatResultTable index 3
			3, // roll 9 maps to combatResultTable index 3
			4, // roll 10 maps to combatResultTable index 4
			5, // roll 11 maps to combatResultTable index 5
			6, // roll 12 maps to combatResultTable index 6
			7, // roll 13 maps to combatResultTable index 7
			8, // roll 14 maps to combatResultTable index 8
			9, // roll 15 maps to combatResultTable index 9
			10, // roll 16 maps to combatResultTable index 10
			11, // roll 17 maps to combatResultTable index 11
												};
	/**
	 * Gets combat results from the combat results table.
	 * @param roll the attacker's roll
	 * @param weaponType the attacker's weapon type
	 * @return int
	 */
	public int getCombatResults(final int roll, final int weaponType) {
		int damage = 0;
		if (roll > maxRoll) {
			damage = combatResultTable[rollMap[maxRoll]][weaponType];
		} else {
			damage = combatResultTable[rollMap[roll]][weaponType];
		}
		return damage;
	}
}
